<template>
  <div class="matter">
    <div class="contain-header">
      <span>评价建议管理<i class="arrow"></i></span>
    </div>
    <div class="contain-body clearfix">
      <div class="list-cont normal-shadow">
        <el-table :data="feedbackData" border style="width: 100%">
          <el-table-column prop="login" label="用户名称" width="180"></el-table-column>
          <el-table-column label="用户类型" width="180">
            <template scope="scope">
              {{mapping(scope.row.user_type, options, 'id', 'name')}}
            </template>
          </el-table-column>
          <el-table-column prop="content" label="评论内容"></el-table-column>
          <el-table-column prop="addtime" label="评论时间"></el-table-column>
          <el-table-column label="操作">
            <template scope="scope">
              <el-button class="bj-btn" size="small" @click="contTop(scope.$index, scope.row)"><i class='glyphicon glyphicon-top'></i></el-button>
              <el-button class="bj-btn" size="small" @click="deleteFeedback(scope.row.id)"><i class="glyphicon glyphicon-delete"></i></el-button>
              <!--<el-button class="bj-btn" size="small" @click="deleteCompany" @click="handleEdit(scope.$index, scope.row)"><i class="glyphicon glyphicon-delete"></i></el-button>-->
            </template>
          </el-table-column>
        </el-table>
      </div>

      <!--分页-->
      <div class="pagination">
        <el-pagination
          @current-change="handleCurrentChange" :page-size="page" layout="prev, pager, next, jumper" :total="totalPage">
        </el-pagination>
      </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'matter',
  data () {
    return {
      feedbackData: [],
      options: [],
      listLoading: false,
      page: 1,
      totalPage: 1,
      params: {
        page: 1
      }
    }
  },
  methods: {
    contTop: function (index, row) {
      this.$message({
        type: 'error',
        message: '此功能暂时无效!'
      })
    },
    mapping (id, array, name1, name2) {
      let needName
      array.forEach(function (item) {
        if (item[name1] === id) {
          needName = item[name2]
          return
        }
      })
      return needName
    },
    getLevelType () {
      this.$http('get', 'level')
        .then((data) => {
          this.options = data.result
        })
    },
    // 获取feedback列表
    getFeedback () {
      this.listLoading = true
      this.$http('get', 'feedback', this.params)
        .then((data) => {
          this.listLoading = false
          this.feedbackData = data.result.dataList
          var total = data.result.total % 10 === 0 ? parseInt(data.result.total / 10) : parseInt(data.result.total / 10) + 1
          this.totalPage = total
        })
    },
    handleCurrentChange (val) {
      this.params.page = val
      this.getFeedback()
    },
    // 删除
    deleteFeedback: function (id) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.listLoading = true
        this.$http('delete', 'feedback', {id: id})
          .then((data) => {
            this.listLoading = false
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
            this.getFeedback()
          })
      }).catch(() => {

      })
    }
  },
  mounted () {
    this.getFeedback()
    this.getLevelType()
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  i{
    color: #58b5ff;
    font-size: 18px;
  }
  .bj-btn{
    border:0;
    width:19px;
    height:19px;
    padding: 0;
  }
  .bj-img{
    width:100%;
    height:100%;
  }
</style>
